<template>
	<view class="container">
		<uni-notice-bar showIcon text="此处展示的爆款视频仅用预览,备:爆款视频的结果只能保持7天,请妥善保存并及时发布"></uni-notice-bar>
		<view class="item" :key="index">
			<image src="../../static/images/load.jpg" style="box-shadow: 2px 2px 4px rgba(0, 0, 0, 0.5);" v-if="videoInfo.videoStatus != 'Success'"></image>
			<video :src="videoInfo.video" class="video" v-if="videoInfo.videoStatus == 'Success'" @click="openVideo(videoInfo)"></video>
		</view>
		
		
		<view class="footer">
			<view class="box right" @click="markAllVideo">生成剩余视频</view>
			<view class="box left" @click="markQrcode">生成二维码发布</view>
		</view>
	</view>
</template>

<script>
	import Http from "@/utils/http"
	const app = getApp()
	const http = new Http()
	export default {
		data() {
			return {
				shopId:'',
				videoList:[],
				baseHttp:'',
				id:'',
				videoInfo:{}
			}
		},
		mounted() {
			this.shopId = app.globalData.shopId;
			this.baseHttp = app.globalData.baseHttp; // 输出 '我是全局变量'
		},
		onLoad(option) {
			this.id = option.id
			this.sendRequire();
			uni.$on('can',(id)=>{
				this.id = id
			})
		},
		onUnload() {
			var pages = getCurrentPages();
			var currentPage = pages[pages.length-2]
			console.log(currentPage);
			console.log(currentPage.route == "subpkg/mkvideo/darenkoubo");
			if(currentPage.__route__ == "subpkg/mkvideo/darenkoubo"){
				
			}else{
				uni.redirectTo({
				    url: '/subpkg/mkvideo/darenkoubo'
				});
			}
			
		},
		onPullDownRefresh() {
				this.sendRequire();
				setTimeout(function () {
					uni.stopPullDownRefresh();
				}, 1000);
		},
		methods: {
			markAllVideo(){
				uni.showModal({
					title:"是否生成剩余视频",
					success: (confirm) => {
					  if(confirm.confirm){
						  http.post('v1/jiaoben/markAllVideo',{
						  	jobId: this.videoInfo.jobId
						  }).then(res=>{
							  console.log("==========",res);
							  
						  	    if(res.data.code!=200){
						  			return uni.showToast({
						  				title:res.data.msg,
						  				icon:"none"
						  			})
						  		}else{
						  			uni.navigateBack({delta:1})
						  		}
						  	})
					  }	
					}
				})
			
			},
			sendRequire(){
				http.get('v1/jiaoben/'+this.id).then(res=>{
					this.videoInfo = res.data.data
				})
			},
			openVideo(data){
				uni.navigateTo({
					url:'/subpkg/bopage/bopage?id=' + data.id
				})
			},
			markQrcode(){
				uni.showToast({
					title:"功能正在开发中",
					icon:"error"
				})
			}
		}
	}
</script>

<style scoped lang="scss">
	page {
		background: #f1f1f1;
	}
	.container{
		padding: 20rpx;
		display: flex;
		flex-wrap: wrap;
		justify-content: space-between;
		.item{
			width: 45%;
			height: 500rpx;
			border-radius: 20rpx;
			margin-bottom: 10rpx;
			position: relative;
			image{
				position: absolute;
				width: 100%;
				height: 100%;
				z-index: 99;
				background-color: white;
			}
			.video{
				width: 100%;
				height: 100%;
			}
		}
	}
.footer{
	position: fixed;
	bottom: 0;
	left:0;
	right: 0;
	height: 100rpx;
	background: #fff;
	display: flex;
	align-items: center;
	justify-content: space-between;
	padding: 0 30rpx;
	.box{
		width: 45%;
		height: 70rpx;
		line-height: 70rpx;
		text-align: center;
		border-radius: 35rpx;
		
	}
	.left{
		background: rgb(14, 16, 101);
		color: #fff;
		font-size: 32rpx;
	}
	.right{
		color: rgb(14, 16, 101);
		border:1rpx solid rgb(14, 16, 101);
		font-size: 32rpx;
	}
}
</style>